Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class com.sun.java.swing.text.PlainView

java.lang.Object
  |
  +--com.sun.java.swing.text.View
        |
        +--com.sun.java.swing.text.PlainView
Subclasses:
FieldView

public class PlainView
extends View
implements TabExpander
Implements View interface for a simple multi-line text view that has text in one font and color. The view represents each child element as a line of text.

See Also:
View

Field Summary
java.awt.FontMetrics metrics
          Font metrics for the currrent font.
 
Fields inherited from class com.sun.java.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
 
Constructor Summary
PlainView(Element elem)
          Constructs a new PlainView wrapped on an element.
 
Method Summary
void changedUpdate(DocumentEvent changes, java.awt.Shape a, ViewFactory f)
          Gives notification from the document that attributes were changed in a location that this view is responsible for.
void drawLine(int lineIndex, java.awt.Graphics g, int x, int y)
          Renders a line of text, suppressing whitespace at the end and exanding any tabs.
int drawSelectedText(java.awt.Graphics g, int x, int y, int p0, int p1)
          Renders the given range in the model as selected text.
int drawUnselectedText(java.awt.Graphics g, int x, int y, int p0, int p1)
          Renders the given range in the model as normal unselected text.
Segment getLineBuffer()
          Gives access to a buffer that can be used to fetch text from the associated document.
int getLineLimit()
          Returns the max number of characters per line set for the document, If none is set, it is computed by examining all lines to find the longest line.
float getPreferredSpan(int axis)
          Determines the preferred span for this view along an axis.
int getTabSize()
          Returns the tab size set for the document, defaulting to 8.
void insertUpdate(DocumentEvent changes, java.awt.Shape a, ViewFactory f)
          Gives notification that something was inserted into the document in a location that this view is responsible for.
java.awt.Shape modelToView(int pos, java.awt.Shape a)
          Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
float nextTabStop(float x, int tabOffset)
          Returns the next tab stop position after a given reference position.
void paint(java.awt.Graphics g, java.awt.Shape a)
          Renders using the given rendering surface and area on that surface.
void preferenceChanged(View child, boolean width, boolean height)
          Signals that the desired span has changed.
void removeUpdate(DocumentEvent changes, java.awt.Shape a, ViewFactory f)
          Gives notification that something was removed from the document in a location that this view is responsible for.
void setParent(View p)
          Sets the parent of the view.
int viewToModel(float fx, float fy, java.awt.Shape a)
          Provides a mapping from the view coordinate space to the logical coordinate space of the model.
 
Methods inherited from class com.sun.java.swing.text.View
breakView, changedUpdate, createFragment, getAlignment, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getParent, getPreferredSpan, getResizeWeight, getStartOffset, getViewCount, getViewFactory, getView, insertUpdate, modelToView, paint, preferenceChanged, removeUpdate, setParent, setSize, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

metrics

protected java.awt.FontMetrics metrics
Font metrics for the currrent font.
Constructor Detail

PlainView

public PlainView(Element elem)
Constructs a new PlainView wrapped on an element.
Parameters:
elem - the element
Method Detail

getTabSize

protected int getTabSize()
Returns the tab size set for the document, defaulting to 8.
Returns:
the tab size

getLineLimit

protected int getLineLimit()
Returns the max number of characters per line set for the document, If none is set, it is computed by examining all lines to find the longest line.
Returns:
the max number

drawLine

protected void drawLine(int lineIndex,
                        java.awt.Graphics g,
                        int x,
                        int y)
Renders a line of text, suppressing whitespace at the end and exanding any tabs. This is implemented to make calls to the methods drawUnselectedText and drawSelectedText so that the way selected and unselected text are rendered can be customized.
Parameters:
lineIndex - the line to draw >= 0
g - the graphics context
x - the starting X position >= 0
y - the starting Y position >= 0
See Also:
drawUnselectedText, drawSelectedText

drawUnselectedText

protected int drawUnselectedText(java.awt.Graphics g,
                                 int x,
                                 int y,
                                 int p0,
                                 int p1)
                         throws BadLocationException
Renders the given range in the model as normal unselected text. Uses the foreground or disabled color to render the text.
Parameters:
g - the graphics context
x - the starting X coordinate >= 0
y - the starting Y coordinate >= 0
p0 - the beginning position in the model >= 0
p1 - the ending position in the model >= 0
Throws:
BadLocationException - if the range is invalid

drawSelectedText

protected int drawSelectedText(java.awt.Graphics g,
                               int x,
                               int y,
                               int p0,
                               int p1)
                       throws BadLocationException
Renders the given range in the model as selected text. This is implemented to render the text in the color specified in the hosting component. It assumes the highlighter will render the selected background.
Parameters:
g - the graphics context
x - the starting X coordinate >= 0
y - the starting Y coordinate >= 0
p0 - the beginning position in the model >= 0
p1 - the ending position in the model >= 0
Throws:
BadLocationException - if the range is invalid

getLineBuffer

protected final Segment getLineBuffer()
Gives access to a buffer that can be used to fetch text from the associated document.

setParent

public void setParent(View p)
Sets the parent of the view. The parent calls this on the child to tell it who its parent is. If this is null, the view has been removed and we need to remove the associated component from its parent. This is used here to determine what the hosting component is.
Parameters:
p - the parent view
Overrides:
setParent in class View

getPreferredSpan

public float getPreferredSpan(int axis)
Determines the preferred span for this view along an axis.
Parameters:
axis - may be either View.X_AXIS or View.Y_AXIS
Throws:
java.lang.IllegalArgumentException - for an invalid axis
Overrides:
getPreferredSpan in class View

paint

public void paint(java.awt.Graphics g,
                  java.awt.Shape a)
Renders using the given rendering surface and area on that surface. The view may need to do layout and create child views to enable itself to render into the given allocation.
Parameters:
g - the rendering surface to use
a - the allocated region to render into
Overrides:
paint in class View
See Also:
paint

preferenceChanged

public void preferenceChanged(View child,
                              boolean width,
                              boolean height)
Signals that the desired span has changed.
Parameters:
child - the child view
width - true if the width preference has changed
height - true if the height preference has changed
Overrides:
preferenceChanged in class View
See Also:
revalidate

modelToView

public java.awt.Shape modelToView(int pos,
                         java.awt.Shape a)
                          throws BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
Parameters:
pos - the position to convert >= 0
a - the allocated region to render into
Returns:
the bounding box of the given position
Throws:
BadLocationException - if the given position does not represent a valid location in the associated document
Overrides:
modelToView in class View
See Also:
modelToView

viewToModel

public int viewToModel(float fx,
                       float fy,
                       java.awt.Shape a)
Provides a mapping from the view coordinate space to the logical coordinate space of the model.
Parameters:
fx - the X coordinate >= 0
fy - the Y coordinate >= 0
a - the allocated region to render into
Returns:
the location within the model that best represents the given point in the view >= 0
Overrides:
viewToModel in class View
See Also:
viewToModel

insertUpdate

public void insertUpdate(DocumentEvent changes,
                         java.awt.Shape a,
                         ViewFactory f)
Gives notification that something was inserted into the document in a location that this view is responsible for.
Parameters:
changes - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
Overrides:
insertUpdate in class View
See Also:
insertUpdate

removeUpdate

public void removeUpdate(DocumentEvent changes,
                         java.awt.Shape a,
                         ViewFactory f)
Gives notification that something was removed from the document in a location that this view is responsible for.
Parameters:
changes - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
Overrides:
removeUpdate in class View
See Also:
removeUpdate

changedUpdate

public void changedUpdate(DocumentEvent changes,
                          java.awt.Shape a,
                          ViewFactory f)
Gives notification from the document that attributes were changed in a location that this view is responsible for.
Parameters:
changes - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
Overrides:
changedUpdate in class View
See Also:
changedUpdate

nextTabStop

public float nextTabStop(float x,
                         int tabOffset)
Returns the next tab stop position after a given reference position. This implementation does not support things like centering so it ignores the tabOffset argument.
Specified by:
nextTabStop in interface TabExpander
Parameters:
x - the current position >= 0
tabOffset - the position within the text stream that the tab occurred at >= 0.
Returns:
the tab stop, measured in points >= 0

Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Submit a bug or feature
Submit comments/suggestions about javadoc
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.